package pumps

import (
	"context"

	"gitee.com/youkelike/ziam/zanalytics"
	"gitee.com/youkelike/ziam/zerrors"
)

var availablePumps map[string]Pump

// 借用 init 实现的单例
func init() {
	availablePumps = make(map[string]Pump)

	// Register all the storage handlers here
	availablePumps["csv"] = &CSVPump{}
	// availablePumps["mongo"] = &MongoPump{}
	availablePumps["dummy"] = &DummyPump{}
	availablePumps["elasticsearch"] = &ElasticsearchPump{}
	availablePumps["influx"] = &InfluxPump{}
	availablePumps["prometheus"] = &PrometheusPump{}
	availablePumps["kafka"] = &KafkaPump{}
	// availablePumps["syslog"] = &SyslogPump{}
}

type Pump interface {
	GetName() string
	New() Pump
	Init(interface{}) error
	WriteData(context.Context, []interface{}) error
	SetFilters(zanalytics.AnalyticsFilters)
	GetFilters() zanalytics.AnalyticsFilters
	SetTimeout(timeout int)
	GetTimeout() int
	SetOmitDetailedRecording(bool)
	GetOmitDetailedRecording() bool
}

func GetPumpByName(name string) (Pump, error) {
	if p, ok := availablePumps[name]; ok && p != nil {
		return p, nil
	}

	return nil, zerrors.New(name + " not found")
}
